package org.school.configuration;

import org.school.Interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class LoginConfig implements WebMvcConfigurer {
    @Resource
    private LoginInterceptor loginInterceptor;

    //不拦截的请求
    String[] excludePatterns = {
            "/loginHost","/loginUser","/regUser","/regHost","/cai/all"};

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println("进入拦截器");
        // 添加拦截器
        registry.addInterceptor(loginInterceptor)
                // 要拦截的请求（所有请求）
                .addPathPatterns("/**")
                // 排除的拦截请求
                .excludePathPatterns(excludePatterns);


    }
}